﻿@{
    Html.EnableClientValidation();
    Html.EnableUnobtrusiveJavaScript();

    var grid = @Html.DevExpress().GridView(
        settings => {
            settings.Name = "detailGridView_" + ViewData["IdReceta"];
            settings.CallbackRouteValues = new { Controller = "Receta", Action = "EditRecetaDetallePartial", IdReceta = ViewData["IdReceta"] };
            settings.SettingsEditing.AddNewRowRouteValues = new { Controller = "Receta", Action = "EditRecetaDetalleAddNewPartial", IdReceta = ViewData["IdReceta"] };
            settings.SettingsEditing.UpdateRowRouteValues = new { Controller = "Receta", Action = "EditRecetaDetalleUpdatePartial", IdReceta = ViewData["IdReceta"] };
            settings.SettingsEditing.DeleteRowRouteValues = new { Controller = "Receta", Action = "EditRecetaDetalleDeletePartial", IdReceta = ViewData["IdReceta"] };
            settings.SettingsEditing.Mode = GridViewEditingMode.PopupEditForm;
            settings.SettingsBehavior.ConfirmDelete = true;

            settings.Width = 600;
            
            settings.SettingsPopup.EditForm.Width = 600;
            settings.SettingsPopup.EditForm.HorizontalAlign = PopupHorizontalAlign.Center;
            settings.SettingsPopup.EditForm.VerticalAlign = PopupVerticalAlign.WindowCenter;

            settings.CommandColumn.Visible = true;
            settings.CommandColumn.ShowNewButtonInHeader = true;
            settings.CommandColumn.ShowEditButton = true;
            settings.CommandColumn.ShowDeleteButton = true;

            settings.KeyFieldName = "IdRecetaDetalle";            

            settings.Columns.Add(
                column =>
                {
                    column.FieldName = "Insumo.IdInsumo";
                    column.Caption = "Insumo";

                    column.ColumnType = MVCxGridViewColumnType.ComboBox;
                    var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                    comboBoxProperties.DataSource = ViewBag.Insumo;
                    comboBoxProperties.TextField = "Nombre";
                    comboBoxProperties.ValueField = "IdInsumo";
                    comboBoxProperties.ValueType = typeof(int);
                    comboBoxProperties.DropDownStyle = DropDownStyle.DropDown;
                });


            settings.Columns.Add("Cantidad");
            
         });

    if (ViewData["EditError"] != null){
        grid.SetEditErrorText((string)ViewData["EditError"]);
    }    
}

@grid.Bind(Model).GetHtml()
    




